function FormalWindow(ptitle,psubtitle){
	Component.apply(this,['<div class="col-xs-12 column">']);	 
	this.titleW = ptitle;
	this.icone = "file";
	var fnCalled = arguments.callee.caller;
	this._fnName = (fnCalled.name)?fnCalled.name.toLowerCase():fnCalled.toString();
	this._moduleName = "view/"+this._fnName+".js";
	this._revision = "0";
	this.subtitleW = "&nbsp;&#160;";
	this._services_lists = [];
	this._loaded = false;
	if(psubtitle){
		this.subtitleW=psubtitle;
	}	
	this.htmlX.attr("id","uid_"+this.uid).css({"z-index":(this.uid-this.uid)+1,"padding":"5px"});//,"padding":"5px"
	this.appendChildX = function(childtoappend){
		this.htmlX.append(childtoappend.htmlX);
	};
	this.setIcon = function(picon){
		this.icone = picon;
	};
	this.setSize=function(nsize){
		var classes = this.htmlX.attr("class");
		var ns = classes.replace(/col\-xs\-(\d{1,2})/,"col-xs-"+nsize);
		this.htmlX.removeClass().addClass(ns);
	};
	this.htmlX.addClass("FormalWindow windowC");
	this.htmlX.append('<h3 class="">'+this.subtitleW+'</h3>');
	this.htmlX.append('<div class="conteudo_form" style="">'+//background-color:#fff;
					  	'<div class="form-group fbody">'+
						'</div>'+
					  	'<div style="padding:15px 0px 15px 0px" class="col-sm-12 form-actions"></div>'+
					  '</div>');
	//this.htmlX.append('<div class=""></div>');
	this.htmlX.append('<div class="blockrequest normal_load"><div class="BoxTasks" style="display:none"></div></div>');
	this.htmlX.append('<blockquote class="col-xs-12 column block_module_details"><p></p></blockquote>');
	this.htmlX[0]["dta"] = this;
	this.append = function(childtoappend,pbrokenline){
		if(childtoappend.htmlX.hasClass("btn")){	
			this.htmlX.find(".form-actions:first").append(childtoappend.htmlX);
		}else if(childtoappend.htmlX.hasClass("DataGrid")||childtoappend.htmlX.hasClass("TileGrid")){
			this.htmlX.find(".fbody:first").append(childtoappend.htmlX);    
		}else if(childtoappend.htmlX.hasClass("ToolBar")){
			this.htmlX.find(".conteudo_form:first").prepend(childtoappend.htmlX);
		}else if(childtoappend.htmlX.hasClass("preview-pane")){
			this.htmlX.find(".fbody:first").append(childtoappend.htmlX);
		}else{
			this.htmlX.find(".fbody:first").append(childtoappend.htmlX);			
			if(childtoappend.htmlX.hasClass("DataFind")){			
				this._services_lists[this._services_lists.length] = childtoappend.uid;
			}
		}
	};
}

FormalWindow.prototype = Object.create(Component.prototype);
FormalWindow.prototype.constructor = FormalWindow;

FormalWindow.prototype.loadServices=function(){
	if(!this._loaded){
		var tmlservices = this._services_lists.length;
		for(var i = 0 ;i<tmlservices;i++){
			var eleTmp = $("#uid_"+this._services_lists[i])[0]["dta"];
			eleTmp.loadServiceOnce(this._fnName);
		};	
		this._loaded = true;
	};
	//childtoappend.loadServiceOnce(this._fnName);
};
FormalWindow.prototype.onlyShow = function(on){
	if(on){
		this.htmlX.show();	
		this.loadServices();			
		this.setDsModule();
	}
};
FormalWindow.prototype.setDsModule=function(){
	this.htmlX.find(".block_module_details").html("<p>"+this._moduleName.replace("/view/","/").replace(/(\w*\/){4}/,"").replace(".js","").toUpperCase().replace(/\//," | ")+" :"+this._revision.replace(/[^\d]+/g,'')+"</p>");
};
FormalWindow.prototype.onlyAppend = function(){		
	$("#conteudo").append(this.htmlX);
};
FormalWindow.prototype.show = function(on,pshowbtnremove){
	if($("#uid_"+this.uid).length  == 0 && on){
		$("#navbarlist > li:first.active").removeClass("active");
		var LinkAbaCloser = $('<li  class="active"></li>');
		LinkAbaCloser.append('<a href="#" id="btn_remove_'+this.uid+'" class="btnsabapages"><span class="glyphicon glyphicon-'+this.icone+'"></span> '+this.titleW+' </a>');

		if(pshowbtnremove){
			LinkAbaCloser.find('a').append('<span class="x_rmv">&otimes;</span>');
		}
		$("#navbarlist").append(LinkAbaCloser);
		$("#conteudo").prepend(this.htmlX);		
		this.htmlX.find(".blockrequest").click(function(){
			rm.showAllTasks(this);
		}).on("dblclick",function(){
			rm.removeAllTasks(this);
		});
		this.loadServices();			
		this.setDsModule();
	}		
	if(on){			
		//if(!pshowbtnremove){
			$('#btn_remove_'+this.uid).show();
		//}
		$("#btn_remove_"+this.uid).click();
		//$("#conteudo .FormalWindow").hide();
		//this.htmlX.show().animate({"opacity":0.2}).delay(210).animate({"opacity":0.4}).delay(210).animate({"opacity":1.0});
	}else{
		this.htmlX.hide();
		if(!pshowbtnremove){
			$('#btn_remove_'+this.uid).hide();
		}
	}
};

$(function(){
	$("#logo_menu").click(function(){
		$("#sidebar li.navitem_simple").removeClass("navitem_simple");
		$("#sidebar").parents("div.menu_main").find(".tab_content_menu ul").hide();		
	});
	$("#sidebar").on('click','li',function(){
		var esse_ = $(this);
		$("#sidebar li.navitem_simple").removeClass("navitem_simple");
		esse_.addClass("navitem_simple");
		$("#sidebar").parents("div.menu_main").find(".tab_content_menu ul").hide();
		$("#"+esse_.attr("id")+"_l").show();
	});
	
	$("#navbarlist").on('click','li',function(){
		$("#conteudo .FormalWindow").removeClass("windowCA").hide();
		$("#navbarlist li.active").removeClass("active");
		var esse_ = $(this).find('a');
		esse_.parents("li").addClass("active");
		var idEle = "#uid_"+esse_.attr("id");
		idEle = idEle.replace("btn_remove_","");
		$(idEle).addClass("windowCA").show();
		//alert(idEle.replace("#uid_",""));
		$("#conteudo ._"+idEle.replace("#uid_","")).show();
		$("#title_mobille_view").html(esse_.text());
		//alert();
	});
	
	$("#navbarlist").on('click','li a span.x_rmv',function(){
		//$("#conteudo .FormalWindow").hide();								
		var esse_ = $(this);				
		var idEle = "#uid_"+esse_.parent().attr("id").replace("btn_remove_","");
		$(idEle).remove();
		esse_.parent().remove();
		$("#navbarlist li:first a.btnsabapages").click();
		//alert();
	});	
	
	$(".tab_content_menu").on('click','li',function(event){
			var _linkM = $(this);
			var fitmp = _linkM[0]["evt"];
			var nextload = false;
			var moduleToLoad = fitmp["tela"].toLowerCase(); 			
			if(!_linkM.hasClass("loading_module")){				
				_linkM.addClass("loading_module");
				nextload = true;
			}else if(window[moduleToLoad]){
				nextload = true;
			}			
			if(nextload){
				_.loadModule({"mod":fitmp["tela"],"url":fitmp["caminho"],"act":fitmp["fn"]});
			}			
	});
	
	
});



